package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@Api(tags = "护理等级管理")
@RequestMapping("/nursingLevel")
public class NursingLevelController {

    @Autowired
    private NursingLevelService nursingLevelService;

    /**
     * 护理等级分页查询
     * @param pageNum
     * @param pageSize
     * @param name
     * @param status
     * @return
     */
    @GetMapping("/listByPage")
    public ResponseResult getList(@RequestParam Integer pageNum,
                                  @RequestParam Integer pageSize,
                                  @RequestParam(required = false) String name,
                                  @RequestParam(required = false) Integer status){
        log.info("护理等级分页查询接口，入参pageNum={},pageSize={},name={},status={}",pageNum,pageSize,name,status);
        PageResponse<NursingLevelVo> pageResponse = nursingLevelService.getList(pageNum,pageSize,name,status);
        return ResponseResult.success(pageResponse);
    }

    /**
     * 新增护理等级
     * @param levelDto
     * @return
     */
    @PostMapping("/insert")
    public ResponseResult addNursingLevel(@RequestBody NursingLevelDto levelDto){
        log.info("新增护理等级接口,入参={}",levelDto);
        nursingLevelService.addNursingLevel(levelDto);
        return ResponseResult.success();
    }

    /**
     * 根据id查询护理等级
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseResult<NursingLevelVo> getById(@PathVariable Long id){
        log.info("根据id查询接口,入参id={}",id);
        NursingLevelVo nursingLevelVo = nursingLevelService.getById(id);
        return ResponseResult.success(nursingLevelVo);
    }

    /**
     * 更新护理等级
     * @param levelDto
     * @return
     */
    @PutMapping("/update")
    public ResponseResult updateNursingLevel(@RequestBody NursingLevelDto levelDto){
        log.info("更新护理等级接口,入参={}",levelDto);
        nursingLevelService.updateNursingLevel(levelDto);
        return ResponseResult.success();
    }

    /**
     * 删除护理等级
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public ResponseResult deleteNursingLevel(@PathVariable Long id){
        log.info("删除护理等级接口，入参id={}",id);
        nursingLevelService.deleteNursingLevel(id);
        return ResponseResult.success();
    }

    /**
     * 更新启停状态
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    public ResponseResult updateStatus(@PathVariable Long id,
                                       @PathVariable Integer status){
        log.info("更新启停状态接口，入参id={}，status={}",id,status);
        nursingLevelService.updateStatus(id,status);
        return ResponseResult.success();
    }
}
